package org.devocean.groupbuying.service.impl;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.devocean.groupbuying.dao.MerchantDAO;
import org.devocean.groupbuying.domain.Merchant;
import org.devocean.groupbuying.service.MerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class MerchantServiceImpl implements MerchantService {

	@Autowired
	private MerchantDAO merchantDAO;
	
	@Transactional
	public Merchant getMerchantById(Integer id) {
		
		return merchantDAO.findMerchantById(id);
	}

	@Transactional
	public Merchant addOrUpdateMerchant(Merchant merchant) {
		if (merchant.getMerchantID() == null) {
			return merchantDAO.saveMerchant(merchant);
		} else {
			return merchantDAO.updateMerchant(merchant);
		}
	}

	
	@Transactional
	public void removeMerchant(Integer id) {
		merchantDAO.deleteMerchant(id);
		
	}

	
	@Transactional
	public long countMerchants() {
		
		return merchantDAO.countMerchants();
	}

	
	@Transactional
	public List<Merchant> getAllMerchants() {
		
		return merchantDAO.findAllMerchants();
	}
	@Transactional
	public List<Merchant> getMerchantsEntries(int start, int size) {
		
		
		return merchantDAO.findMerchantsEntries(start, size);
	}

	@Transactional
	public List<Merchant> getMerchantsByCriteria(String query, Integer start,
			Integer size) {
		
		return merchantDAO.findMerchantByCriteria(query,start,size);
	}

	@Transactional
	public long countMerchantsBycriteria(String criteria) {
		
		return merchantDAO.countMerchantsByCriteria(criteria);
	}

	public Map<String, Object> search(String searchText,
			ConcurrentHashMap<String, Object> searchResult) {
		return searchResult;
	}
	

}
